package com.iot.comprehensive.face.controller;

import com.iot.comprehensive.face.model.Account;
import com.iot.comprehensive.face.model.Host;
import com.iot.comprehensive.face.model.ImgPath;
import com.iot.comprehensive.face.model.User;
import com.iot.comprehensive.face.service.HostService;
import com.iot.comprehensive.face.service.ImgPathService;
import com.iot.comprehensive.face.service.UserService;
import com.iot.comprehensive.face.utils.Result;
import com.iot.comprehensive.face.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 朱泽玉
 * @Create 2021/7/4 15:10
 * @Description
 * @Modified By:
 */
@RestController
@RequestMapping("/img")
public class ImgPathController {
    @Autowired
    final ImgPathService imgPathService;
    final UserService userService;
    final HostService hostService;
    public ImgPathController(ImgPathService imgPathService, UserService userService, HostService hostService) {
        this.imgPathService = imgPathService;
        this.userService = userService;
        this.hostService = hostService;
    }

    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    @ResponseBody
    public Result delAll() {
//        imgPathService.del();
        return new Result(ResultCode.SUCCESS);
    }

    public void add(Account account){
        ImgPath imgPath = new ImgPath();
        Host host = hostService.findById(account.getId());
        User user = userService.getByAccount(account.getId());
        String path = "https://192.168.43.142:21625/host/getimg/"+account.getMobile();
        host.setImg_path(path);

        imgPath.setUser(account.getId());
        imgPath.setName(user.getName());
        imgPath.setPath(path);
        hostService.save(host);
        imgPathService.add(imgPath);
    }
}
